<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex addChapter_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between addChapter_fd0_0'>
					<view class='flex flex-wrap align-center addChapter_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  addChapter_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-center'>
						<text class='addChapter_fd0_0_c1_c0'>添加章节</text>
					</view>
					<view class='flex align-center justify-end addChapter_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addChapter_flex_1">
				<view class='flex flex-wrap align-center addChapter_fd1_0'>
					<text class='addChapter_fd1_0_c0'>章节名称</text>
					<benben-input class='flex-sub addChapter_fd1_0_c1' type="text" :placeholder="`请输入章节名称`"
						confirm-type="done" :maxlength="-1"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="chapterData.wenben" />
				</view>
				<text class='addChapter_fd1_1'>章节描述</text>
				<view class='flex flex-wrap addChapter_fd1_2'>
					<textarea class='flex addChapter_input_fd1_2' :placeholder="'请输入章节描述'" :maxlength="240"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:28rpx"
						v-model="chapterData.describe" />

				</view>
				<text class='addChapter_fd1_3'>章节视频</text>
				<view class='flex flex-wrap align-center'>
					<benben-video-upload-paas ref="upload1696918172184" :upload-data.sync="shiPinData"
						:video-info.sync="chapterData.shipin">
						<template v-slot="{src, poster}">
							<view class='flex position-relative'>
								<image class='addChapter_fd1_4_c0_c0' mode="aspectFill"
									@tap="$refs.upload1696918172184.previewVideo()"
									:src='poster?poster:STATIC_URL+"4.png"'></image>
								<text class='fu-iconfont2 position-absolute addChapter_fd1_4_c0_c1'
									@tap="$refs.upload1696918172184.delVideo()" v-if="src">&#xE8E7;</text>
							</view>
						</template></benben-video-upload-paas>
				</view>
			</view>
			<!---flex布局flex布局结束-->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex addChapter_flex_2">
				<button class='addChapter_fd2_0' @tap.stop="postVideoFunc()">提交</button>

			</view>
			<view :style="{height: '120rpx'}"></view>


		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"shiPinData": "",
				"chapterData": {
					"aid": "",
					"freexianshangkecheng_id": "",
					"wenben": "",
					"cover": "",
					"describe": "",
					"shipin": {
						"name": "",
						"path": "",
						"thumb": "",
						"mime": "",
						"duration": ""
					}
				},
				"course_id": "",
				"shopID": "",
				"chapter_id": ""
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				course_id,
				shopID,
				chapter_id
			} = options
			if (course_id !== undefined) this.course_id = course_id
			if (shopID !== undefined) this.shopID = shopID
			if (chapter_id !== undefined) this.chapter_id = chapter_id
			this.getChapterFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//提交视频
			async postVideoFunc() {
				if (!validate(this.chapterData.wenben, 'require')) {
					this.$message.info('请输入章节名称');
					return false;
				}
				if (!validate(this.chapterData.describe, 'require')) {
					this.$message.info('请输入章节描述');
					return false;
				}
				if (!validate(this.shiPinData, 'require')) {
					this.$message.info('请上传章节视频');
					return false;
				}
				//请求方法
				//数据验证

				let data6524f8b32a98b = await this.$api.dbPost(global.apiUrls.post6524f8b32a98b, {
					aid: this.chapter_id,
					wenben: this.chapterData.wenben,
					shipin: this.shiPinData,
					describe: this.chapterData.describe,
					fid: this.course_id,
					cover: this.chapterData.cover
				});
				if (!data6524f8b32a98b) return
				if (data6524f8b32a98b.data.code != 1) {
					this.$message.info(data6524f8b32a98b.data.msg);
					return
				}



				if (this.chapter_id == '') {
					this.$message.info('添加成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				} else if (this.course_id != '') {
					this.$message.info('修改成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				}
			},
			//获取章节信息
			async getChapterFunc() {
				//请求方法
				//数据验证

				let datachapterData = await this.$api.get(global.apiUrls.post6525032bb47ac, {
					aid: this.chapter_id
				});

				if (datachapterData.data.code != 1) {
					this.$message.info(datachapterData.data.msg);
					return
				}
				let infochapterData = datachapterData.data;
				this.chapterData = infochapterData.data

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto;
	}

	.addChapter_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.addChapter_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.addChapter_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
		font-weight: 500;
	}

	.addChapter_fd0_0_c0 {
		width: 100rpx;
	}

	.addChapter_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
	}

	.addChapter_flex_1 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.addChapter_fd1_4_c0_c1 {
		top: 0rpx;
		right: 0rpx;
		z-index: 10;
		color: #ff5536;
	}

	.addChapter_fd1_4_c0_c0 {
		width: 180rpx;
		height: 180rpx;
		border-radius: 16rpx;
	}

	.addChapter_fd1_3 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
		margin: 24rpx 0rpx 24rpx 0rpx;
	}

	.addChapter_input_fd1_2 {
		width: 100%;
		height: 160rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		white-space: pre-wrap;
	}

	.addChapter_fd1_2 {
		background: rgba(248, 248, 248, 1);
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		padding: 24rpx 24rpx 24rpx 24rpx;
	}

	.addChapter_fd1_1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
		margin: 0rpx 0rpx 24rpx 0rpx;
	}

	.addChapter_fd1_0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.addChapter_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addChapter_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
		margin: 0rpx 0rpx 32rpx 0rpx;
	}

	.addChapter_flex_2 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.addChapter_fd2_0 {
		background: #E31D1A;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
	}
</style>